package praca.gra;

import java.util.Random;

import android.util.Log;

public class Troll {
	public float x;
	public float y;
	float dirX;
	float dirY;
	Random rand = new Random();
	float low = -100;
	float high = 100;
	float rotation;
	float rotateSpeed;
	int width;
	int height;
	public boolean isTouched = false;

	
	public Troll(int width, int height){
		x = rand.nextFloat() * 800;
		y = rand.nextFloat() * 480;
		dirX = rand.nextFloat()*(high-low) + low;
		dirY = rand.nextFloat()*(high-low) + low;
		rotation = rand.nextFloat() * 360;
		rotateSpeed = rand.nextFloat() * 60;
		this.width = width;
		this.height = height;
	}
	
	
	
	public boolean isInside(float u, float v){
		Log.d("touch", "Z ekranu! x: "+u+", y: "+v);
		Log.d("touch", "Troll! x: "+x+", y: "+y);
		
		if(u < x+width/2 && u>x-width/2 && v < y+height/2 && v>y-height/2 ){
			Log.d("touch", "Środek trolla");
			return true;
		}
		else
			return false;
	}
	
	public boolean isTouched(){
		return isTouched;
	}
	
	public void update(float deltaTime) {
		if(!isTouched){
		x = x + dirX * deltaTime;
		y = y + dirY * deltaTime;
		if (x < 0) {
			dirX = -dirX;
			x = 0;
		}
		if (x > 800) {
			dirX = -dirX;
			x = 800;
		}
		if (y < 0) {
			dirY = -dirY;
			y = 0;
		}
		if (y > 480) {
			dirY = -dirY;
			y = 480;
		}
		
		/*
		 * Przyklad uzycia delta Time
		 * mnozac przez delta time(w sekundach) 
		 * kazdy troll bedzie sie obracal rotateSpeed stopni co SEKUNDE
		 */
		rotation = rotation + rotateSpeed*deltaTime;
		if(rotation >= 360)
			rotation = 0;
		}
	}
	
	
}
